class TrialPeriod < ActiveRecord::Base
  belongs_to :bundle_variation
  
  #validates_presence_of :bundle_variation_id, :on =>:create
  validates_presence_of :period
  validates_numericality_of :period, :only_integer => true, :message => "must be an integer"

  # named_scope :by_state, lambda {|status| {:conditions => ["status = ?", status}}
  
  #----- Act as FINITE STATE MACHINE -------------
    acts_as_state_machine :initial => RefActionStatus::ACTIVE, :column => :status
    
    state RefActionStatus::INACTIVE, :column => :status
    state RefActionStatus::ACTIVE, :column => :status
    
    event :activate do
       transitions :from => :inactive, :to => RefActionStatus::ACTIVE
    end

    event :deactivate do
      transitions :from => :active, :to => RefActionStatus::INACTIVE
    end
    
    # reference of statuses for this model
    def self.statuses
      [RefActionStatus::ACTIVE, RefActionStatus::INACTIVE]
    end
  #-----------------------------------------------
  
end
